<%@page import="java.util.ArrayList"%>
<%@page import="com.wanmait.cookbook.vo.Userinfo"%>
<%@page import="jdk.nashorn.internal.ir.RuntimeNode.Request"%>
<%@page import="com.wanmait.cookbook.vo.IngredientsTypeSecond"%>
<%@page import="com.wanmait.cookbook.vo.Works"%>
<%@page import="com.wanmait.cookbook.vo.Cookbook"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>南瓜美食_菜谱_菜谱大全_优质美食社区</title>
<link rel="icon" href="" type="image/x-icon">
<link rel="stylesheet" href="./static/css/main.css">
<link rel="stylesheet" href="./static/css/index.css">
<script type="text/javascript" async="" src="./static/auto_ds"></script>
<script src="./static/js/osd.js.下载"></script>
<script src="./static/f.txt" id="google_shimpl"></script>
<script type="text/javascript" async="" src="./static/js/pr.js.下载"
	id="remoteOldScript"></script>
<script type="text/javascript" async="" src="./static/js/awyczk.js.下载"></script>
<script src="./static/js/hm.js.下载"></script>
<script src="./static/js/jquery.js.下载"></script>
<script data-ad-client="ca-pub-6608973961595981" async=""
	src="./static/f(1).txt" data-checked-head="true"></script>
<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script type="text/javascript"
	src="<%=path%>/static/js/jquery-3.5.1.min.js"></script>
<script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?f4fa5d56f272ae0a0777feec2184a97f";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
<link rel="preload" href="./static/f(2).txt" as="script">
<script type="text/javascript" src="./static/f(2).txt"></script>
</head>
<body>
	<div id="BAIDU_DUP_fp_wrapper"
		style="position: absolute; left: -1px; bottom: -1px; z-index: 0; width: 0px; height: 0px; overflow: hidden; visibility: hidden; display: none;">
		<iframe id="BAIDU_DUP_fp_iframe" src="./static/o.html"
			style="width: 0px; height: 0px; visibility: hidden; display: none;"></iframe>
	</div>
	<jsp:include page="/inc/head.jsp"></jsp:include>
	<style type="text/css">
.blist {
	left: 0 !important;
}
</style>
	<!-- 轮播图展示-->
	<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
	<link href="<%=path%>/static/css/style.css" type="text/css"
		rel="stylesheet">
	<div id="rew">
		<div class="poster-main" style="float: left">
			<div class="poster-btn poster-prev-btn"></div>
			<ul class="poster-list">
			<%
			Userinfo userinfo =(Userinfo)session.getAttribute("userinfo");
			List<Cookbook> carousels=(List<Cookbook>)request.getAttribute("carousels");
			for(int i=0;i<5;i++){
				%>
				
				<li class="poster-item">
					<a href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=carousels.get(i).getId() %>">
						<img  src="<%=path%>/static/image/<%=carousels.get(i).getPic()%>">
						</a> 
					<span class="poster-item-title"></span></li>
				
				<%
			}
			%>
			
			
			
			
			</ul>
			<div class="poster-btn poster-next-btn"></div>
		</div>
	</div>
	<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
	<script src="<%=path%>/static/js/Carousel.js"></script>
	<script>
//$(".poster-main").Carousel("init");

$(".poster-main").Carousel({
"width":1500,		
"height":200,		
"posterWidth":700,	
"posterHeight":400,
"scale":0.85,		
"speed": 1000,	
"autoPlay":true,	
"delay":1500,	
"verticalAlign":"middle"	
});

</script>
	<!-- Swiper2 end -->

	<!-- 轮播图展示结束-->
	<div id="content" class="clearfix">

		<!-- 精选菜谱 -->
		<h2 class="title">
			每日精选菜谱<a class="more"
				href="<%=path%>/HotCookbookShowListServlet?action=getOnePageCookbook">更多
				<img src="<%=path%>/static/image/more2(1).png" alt="">
			</a>
		</h2>
		<ul class="recipe-list clearfix">
			<%
				List<Cookbook> cookbooks = (List<Cookbook>) request.getAttribute("cookbooks");
				List<Integer> cookbookCount=(List<Integer>)request.getAttribute("cookbookCount");

				List<Boolean> isCollects=new ArrayList<>();
				if(userinfo!=null){
					isCollects=(List<Boolean>)request.getAttribute("isCollects");
				}
				for (int i = 0; i < 8; i++) {
					if ((i + 1) % 4 != 0) {
			%>
				<li class="item" ><a class="cover br8"
				href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=cookbooks.get(i).getId() %>" target="_blank"> 
				<img width="220" height="220"
					src="<%=path%>/static/image/<%=cookbooks.get(i).getPic()%>" alt="">
			</a>
				<div >
					<a class="name text-lips" target="_blank" href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=cookbooks.get(i).getId() %>"><%=cookbooks.get(i).getTitle()%></a>
					<p style="height:100" class="author text-lips">
						<span> <img style="width:15px; border-radius: 15px;height:15px"  src="<%=path %>/static/image/<%=cookbooks.get(i).getUserinfo().getAvatar()%>"></span> <a target="_blank" href="<%=path %>/PersonalServlet?action=init&id=<%=cookbooks.get(i).getUserinfo().getId() %>"><%=cookbooks.get(i).getUserinfo().getName()%></a>
						<!-- 收藏开始 -->
						<span>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>
							
							<% if(userinfo!=null){
								boolean is=isCollects.get(i);
								if(is){
									%>
									<span  class="shoucangzi">已收藏</span> 
									<img width="15" data-id="<%=cookbooks.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangshixin.jpg"><%
								}
								else{
									%>
									<span  class="shoucangzi">收藏</span> 
									<img width="15" data-id="<%=cookbooks.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><%
								}
							}else{
								%>
								<span  class="shoucangzi">收藏</span> 
								<img width="15" data-id="<%=cookbooks.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><% 
							}%>
							
								
						
						
						
						<!-- 收藏结束 -->
							
					</p>
				</div></li>
		
			<%
				} else {
			%>
			<li class="item" style="margin-right: 0px"><a class="cover br8"
				href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=cookbooks.get(i).getId() %>" target="_blank"> <img width="220" height="220"
					src="<%=path%>/static/image/<%=cookbooks.get(i).getPic()%>" alt="">
			</a>
				<div >
					<a class="name text-lips" target="_blank"href="<%=path %>/CookbookServlet?action=cookbookShow&id=<%=cookbooks.get(i).getId() %>"><%=cookbooks.get(i).getTitle()%></a>
					<p style="height:100" class="author text-lips">
						<span><img style="width:15px; border-radius: 15px;height:15px" src="<%=path %>/static/image/<%=cookbooks.get(i).getUserinfo().getAvatar()%>"></span> <a target="_blank" href="<%=path %>/PersonalServlet?action=init&id=<%=cookbooks.get(i).getUserinfo().getId() %>"><%=cookbooks.get(i).getUserinfo().getName()%></a>
						<!-- 粉丝开始 -->
						<span>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>
							
							<% if(userinfo!=null){
								boolean is=isCollects.get(i);
								if(is){
									%>
									<span  class="shoucangzi">已收藏</span> 
									<img width="15" data-id="<%=cookbooks.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangshixin.jpg"><%
								}
								else{
									%>
									<span  class="shoucangzi">收藏</span> 
									<img width="15" data-id="<%=cookbooks.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><%
								}
							}else{
								%>
								<span  class="shoucangzi">收藏</span> 
								<img width="15" data-id="<%=cookbooks.get(i).getId() %>" class="shoucang"src="<%=path%>/img/shoucangkongxin.jpg"><% 
							}%>
							
							
							<!-- 粉丝结束 -->

					</p>
				</div></li>
			<%
				}
				}
			%>
		</ul>
		<!-- 作品-->
		<h2 class="title">
			作品<a class="more" href="<%=path%>/HotWorksServlet?action=allOnePagerWorksInc">更多
				<img src="./static/image/more2(1).png" alt="">
			</a>
		</h2>
		<ul class="note-list clearfix">
			<%
				List<Works> allWorks = (List<Works>) request.getAttribute("allWorks");
				List<Integer> worksCollectCounts=(List<Integer>)request.getAttribute("worksCollectCounts");
				for (int i = 0; i < 4; i++) {
					if ((i + 1) % 4 != 0) {
			%>
			<li class="item">
				<a class="cover"  href="<%=path %>/HotWorksServlet?action=showWorks&worksId=<%=allWorks.get(i).getId() %>" target="_blank"
					style="background: url(<%=path%>/static/image/<%=allWorks.get(i).getPic()%>) no-repeat center center; background-size: cover;">
				</a>
				<div class="info">
					<a class="name text-lips" href="<%=path %>/HotWorksServlet?action=showWorks&worksId=<%=allWorks.get(i).getId() %>" target="_blank"><%=allWorks.get(i).getTitle()%></a>
					<a class="author" href="<%=path %>/PersonalServlet?action=init&id=<%=allWorks.get(i).getUserinfo().getId() %>" target="_blank"> <img
						class="headicon br50"
						src="<%=path%>/static/image/<%=allWorks.get(i).getUserinfo().getAvatar()%>">
						<span style="" class="nickname text-lips"><%=allWorks.get(i).getUserinfo().getName()%></span>
					</a>
						<span >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
						</span>
						<span style="" class="nickname text-lips">点赞<%=worksCollectCounts.get(i) %>
							<a class="author"  href="javascriptt:void(0)">
								<img class="likeHeart" width="20" src="<%=path%>/img/kongxin.jpg">
							</a>
						</span>
						<span></span>
					
					
					
				</div></li>
			<%
				} else {
			%>
			<li class="item" style="margin-right: 0px"><a class="cover"  href="<%=path %>/HotWorksServlet?action=showWorks&worksId=<%=allWorks.get(i).getId() %>" target="_blank"
					style="background: url(<%=path%>/static/image/<%=allWorks.get(i).getPic()%>) no-repeat center center; background-size: cover;">
				</a>
				<div class="info">
					<a class="name text-lips" href="<%=path %>/HotWorksServlet?action=showWorks&worksId=<%=allWorks.get(i).getId() %>" target="_blank"><%=allWorks.get(i).getTitle()%></a>
					<a class="author" href="<%=path %>/PersonalServlet?action=init&id=<%=allWorks.get(i).getId() %>" target="_blank"> <img
						class="headicon br50"
						src="<%=path%>/static/image/<%=allWorks.get(i).getUserinfo().getAvatar()%>">
						<span style="" class="nickname text-lips"><%=allWorks.get(i).getUserinfo().getName()%></span>
						</a>
						<span >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
						</span>
						<span style="" class="nickname text-lips">点赞<%=worksCollectCounts.get(i) %>
							<a href="javascriptt:void(0)">
								<img class="likeHeart" width="20" src="<%=path%>/img/kongxin.jpg">
							</a>
						</span>
						<span></span>
					
					
					
				</div></li>
			<%
				}
				}
			%>
		</ul>
		<div id="left">
			<!-- 食材 -->
			<h2 class="title">
				热门食材<a class="more"
					href="<%=path %>/indexServlet?action=getAllIngredientType">更多 <img
					src="./static/more2(1).png" alt=""></a>
			</h2>
			 <ul class="material-list br8">

				<%
					List<IngredientsTypeSecond> ingredientsTypeSeconds = (List<IngredientsTypeSecond>) request
							.getAttribute("ingredientsTypeSeconds");
					for (int i = 0; i <12; i++) {
				%>
				<li class="item"><a href="<%=path %>/indexServlet?action=detailFood&name=<%=ingredientsTypeSeconds.get(i).getTitle() %>" target="_blank"> <img
						class="br4" src="<%=path%>/static/image/<%=ingredientsTypeSeconds.get(i).getPic()%>">
						<%=ingredientsTypeSeconds.get(i).getTitle()%>
				</a></li>
				<%
					}
				%>

			</ul> 


		</div>
		<!-- 达人 -->
		<h2 class="title" style="margin-left: 720px">
			精选达人<a class="more"
				href="<%=path %>/hotUserinfoServlet?action=hotUserinfoShowList">更多
				<img src="./static/image/more2(2).png" alt="">
			</a>
		</h2>
		<ul class="dr-list br8">
			<%
				for (int j = 0; j < 4; j++) {
					
			%>
			<input type="hidden" value="<%=allWorks.get(j).getUserinfo().getId() %>" class="gzz">
			<li class="clearfix" style="margin-left: 20px"><a
				class="headicon left" href="<%=path %>/PersonalServlet?action=init&id=<%=allWorks.get(j).getUserinfo().getId() %>" target="_blank"> 
				<img class="br5" style="border-radius: 46px"
					src="<%=path%>/static/image/<%=allWorks.get(j).getUserinfo().getAvatar()%>"
					height="46" width="46">
			</a>
				<div class="info">
					<div>
						<a class="nickname text-lips" href="<%=path %>/PersonalServlet?action=init&id=<%=allWorks.get(j).getUserinfo().getId() %>" target="_blank"><%=allWorks.get(j).getUserinfo().getName()%></a>

					</div>
					<%--  <p class="fans" style="color: red"><%=worksCollectCounts.get(j) %></p>  --%>
					
					<!-- 粉丝展示 -->
						<span style="" class="nickname text-lips">粉丝<%=worksCollectCounts.get(j) %>

						</span>
					<!-- 粉丝结束 -->
					
				</div> <a class="gz" data-id="<%=allWorks.get(j).getUserinfo().getId()%>" data-action="add" href="javascript:void(0)"
				onclick=" logshow()  "><span class="addicon" id="gz<%=allWorks.get(j).getUserinfo().getId()%>">＋</span> 关注</a></li>
				

			<%
				}
			%>

		</ul>
	</div>
	<div id="module">
		<!-- 模态框 -->
		<div class="smask"></div>
		<!-- 登录框 -->


	</div>
	</div>
	<style>
.title a:hover {
	color: #F4B644;
}
</style>
	<jsp:include page="/inc/foot.jsp"></jsp:include>
	<script type="text/javascript">(function () {
                    document.getElementById('___szfw_logo___').oncontextmenu = function () {
                        return false;
                    }
                })();</script>

	<script type="text/javascript">
		class Swiper {
			constructor() {
				this.w = $('.swiper-item').width();
				this.num = 0;
				this.len = $('.swiper .swiper-item').length - 1;
				this.timer = null;
			}
			init() {
				//设置定时器
				this.setTime();
				//滑上停止定时器
				this.hover();
				//点击指示
				this.pointClick();
				//点击左右箭头
				this.lrClick();
			}
			setTime() {
				this.timer = setInterval(() => { this.num++;	
					if (this.num > this.len) {
						this.num = 0;
					}
					let cssTrx = -this.num * this.w;
					$('.swiper-point-item .point').eq(this.num).addClass('active').siblings().removeClass('active');
					$('.swiper').css({transform: `translateX(${cssTrx}px)`})
				}, 300)
			}
			hover() {
				$('.swiper-contione').hover(() => { clearInterval(this.timer)
				}, () => {
					this.setTime();
				});
			}
			pointClick() {
				let that = this;
				$('.swiper-point-item .point').click(function() {
					that.num = $(this).index();
					let cssTrx = -that.num * that.w;
					$(this).addClass('active').siblings().removeClass('active');
					$('.swiper').css({
						transform: `translateX(${cssTrx}px)`
					})
				})
			}
			lrClick() {
				$('.swiper-left img').click(() => { this.num--;
					if (this.num < 0) {
						this.num = this.len;
					};
				
					let cssTrx = -this.num * this.w;
					$('.swiper-point-item .point').eq(this.num).addClass('active').siblings().removeClass('active');
					$('.swiper').css({
						transform: `translateX(${cssTrx}px)`
					})
				});
				
				$('.swiper-right img').click(() => { this.num++;
					if (this.num > this.len) {
						this.num = 0;
					}
					let cssTrx = -this.num * this.w;
					$('.swiper-point-item .point').eq(this.num).addClass('active').siblings().removeClass('active');
					$('.swiper').css({
						transform: `translateX(${cssTrx}px)`
					})
				})
			}
		}
		let sw = new Swiper();
		sw.init();
	</script>
	<!-- 轮播图点击事件结束-->
	<script type="text/javascript">

 </script>
 <!-- 点赞按钮 事件开始-->
 <script>
$(function(){
	$(".likeHeart").click(function(){
		var likeSrc=$(this).attr("src");
		
		if("/cookbook/img/kongxin.jpg"==likeSrc){
			var likeSrc=$(this).attr("src","<%=path%>/img/shixin.jpg");
		}else{
			var likeSrc=$(this).attr("src","<%=path%>/img/kongxin.jpg");
		}
	});
});
</script>
<!-- 点赞按钮结束 -->
<!-- 收藏事件开始 -->
<script type="text/javascript">
	$(function(){
		$(".shoucang").click(function(){
			var cookbookId=$(this).data("id");
			var zi=$(this);
			var shoucangsrc=$(this).attr("src");
			if(<%=userinfo==null%>){
				location.href="<%=path%>/login.jsp";
			}else{
					if(shoucangsrc=="<%=path%>/img/shoucangkongxin.jpg"){
						$(this).attr("src","<%=path%>/img/shoucangshixin.jpg");
						$.ajax({
							url:"<%=path%>/CookbookCollectServlet", 
							data:{action:"addCollection",cookbookId:cookbookId},
							success:function(){
								zi.prev().html("已收藏")
							}
						}) 
						
						
					}
					else{
						$(this).attr("src","<%=path%>/img/shoucangkongxin.jpg");
						$.ajax({
							url:"<%=path%>/CookbookCollectServlet", 
							data:{action:"cancelCollection",cookbookId:cookbookId},
							success:function(){
								zi.prev().html("收藏")
							}
						})
						
						}
			}
			});
		
		if(<%=userinfo!=null%>){
			$(".gzz").each(function(){
				var aid = $(this).val();
				$.ajax({
					url:"<%=path%>/AttentionServlet",
					data:{action:"judgeAttention",authorId:aid},
					success:function(msg){
						if(msg=="true"){
	        				$("#gz"+aid+"").text("已");
	        			}
	        			else{
	        				$("#gz"+aid+"").text("+");
	        			}
					}
				});
			});
			$(".gz").click(function(){
				var aid =$(this).data("id");
				
				if($("#gz"+aid+"").text()=="+"){
        			$.ajax({
        				url:"<%=path%>/AttentionServlet",
        				data:{action:"addAttention",authorId:aid}
        			});
        			$("#gz"+aid+"").text("已");
        		}
        		else{
        			if(!window.confirm("确定取消关注？")){
        				return;
        			}
        			$.ajax({
        				url:"<%=path%>/AttentionServlet",
        				data:{action:"cancelAttention",authorId:aid}
        			});
        			$("#gz"+aid+"").text("+");
        		}
				
			});
		}
		else{
			$(".gz").click(function(){
				var aid =$(this).data("id");
        		$.ajax({
        			url:"<%=path%>/AttentionServlet",
        			data:{action:"addAttention",authorId:aid},
        			success:function(msg){
        				if("no"==msg){
        					window.location.href="<%=path%>/login.jsp";
        				}
        			}
        		});
        	});
		}
	});
</script>
<!-- 收藏事件结束 -->